{include file="header/index" /}
<div class="newContentBox">

    <form class="layui-form newListPart ">
        <div class="newPart">
            <!-- 关系结构图 -->
            <div class="newTitleBox">
                <span class="layui-inline newListTitle">关系结构图</span>
                <a class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</a>
            </div>
            <div class="newContent">
                <p style="color: red;margin-bottom: 10px;">注：人数越多加载时间越长</p>
                <input type="hidden" id="id" value="{$id}">
                <div class="tree well">

                    <ul id="rootUL">

                    </ul>
                </div>
            </div>
        </div>

    </form>

</div>

<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        tree = layui.tree,
        laytpl = layui.laytpl;
    $.ajaxSetup({headers: {token: $.cookie('token'),company: $.cookie('company_id')}});;

    var loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
    $(function () {
        var request_data = {};
        request_data.id = $("#id").val();
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Dealer/dealerTree",request_data,function (flag) {
            if (flag.code < 0){
                layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                return false;
            }
            Tree(flag.data);

            layer.close(loadingFlag);
            /*$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', '关闭');
            $('.tree li.parent_li > span').on('click', function (e) {
                var children = $(this).parent('li.parent_li').find(' > ul > li');
                if (children.is(":visible")) {
                    children.hide('fast');
                    $(this).attr('title', '展开').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
                } else {
                    children.show('fast');
                    $(this).attr('title', '关闭').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
                }
                e.stopPropagation();
            });
            $('.tree li.parent_li > span').click();*/
        });
        function Tree(data) {
            console.log('123',data)
            tree({
                elem: '#rootUL'
                ,nodes: data
                ,click: function(node){
                    console.log(node) //node即为当前点击的节点数据
                }
            });
            /*for (var i = 0; i < data.length; i++) {
                var data2 = data[i];
                if (data[i].icon == "icon-th") {
                    $("#rootUL").append("<li data-name='" + data[i].code + "'><span><i class='" + data[i].icon + "'></i> " + data[i].name + "</span></li>");
                } else {
                    var children = $("li[data-name='" + data[i].parentCode + "']").children("ul");
                    if (children.length == 0) {
                        $("li[data-name='" + data[i].parentCode + "']").append("<ul></ul>")
                    }
                    $("li[data-name='" + data[i].parentCode + "'] > ul").append(
                        "<li data-name='" + data[i].code + "'>" +
                        "<span>" +
                        "<i class='" + data[i].icon + "'></i> " +
                        data[i].name + '-' +data[i].workers_number+
                        "</span>" +
                        "</li>")
                }
                for (var j = 0; j < data[i].child.length; j++) {
                    var child = data[i].child[j];
                    var children = $("li[data-name='" + child.parentCode + "']").children("ul");
                    if (children.length == 0) {
                        $("li[data-name='" + child.parentCode + "']").append("<ul></ul>")
                    }
                    $("li[data-name='" + child.parentCode + "'] > ul").append(
                        "<li data-name='" + child.code + "'>" +
                        "<span>" +
                        "<i class='" + child.icon + "'></i> " +
                        child.name + '-' +child.workers_number+
                        "</span>" +
                        "</li>")
                    var child2 = data[i].child[j].child;
                    tree(child2)
                }

                tree(data[i]);
            }*/

        }
    });
</script>
